package cn.edu.scau.cmi.ema.domain;


import java.io.Serializable;

import java.lang.StringBuilder;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.persistence.*;
import javax.xml.bind.annotation.*;
import cn.edu.scau.cmi.ema.domain.*;
import java.util.Set;
import com.alibaba.fastjson.annotation.JSONField;

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllEventqualitytypes", query = "select myEventqualitytype from Eventqualitytype myEventqualitytype"),
		@NamedQuery(name = "findEventqualitytypeByName", query = "select myEventqualitytype from Eventqualitytype myEventqualitytype where myEventqualitytype.name = ?1"),
		@NamedQuery(name = "findEventqualitytypeByNameContaining", query = "select myEventqualitytype from Eventqualitytype myEventqualitytype where myEventqualitytype.name like concat('%',?1,'%')"),
		@NamedQuery(name = "findEventqualitytypeByDegree", query = "select myEventqualitytype from Eventqualitytype myEventqualitytype where myEventqualitytype.degree = ?1"),
		@NamedQuery(name = "findEventqualitytypeByDegreeContaining", query = "select myEventqualitytype from Eventqualitytype myEventqualitytype where myEventqualitytype.degree like concat('%',?1,'%')"),
		@NamedQuery(name = "findEventqualitytypeByDescription", query = "select myEventqualitytype from Eventqualitytype myEventqualitytype where myEventqualitytype.description = ?1"),
		@NamedQuery(name = "findEventqualitytypeByDescriptionContaining", query = "select myEventqualitytype from Eventqualitytype myEventqualitytype where myEventqualitytype.description like concat('%',?1,'%')"),
		@NamedQuery(name = "findAllEventqualitytypesByEvent", query = "select myEventqualitytype from Eventqualitytype myEventqualitytype where myEventqualitytype.event.id = ?1"),
		@NamedQuery(name = "findAllEventqualitytypesByQualitytype", query = "select myEventqualitytype from Eventqualitytype myEventqualitytype where myEventqualitytype.qualitytype.id = ?1"),
		@NamedQuery(name = "findEventqualitytypeById", query = "select myEventqualitytype from Eventqualitytype myEventqualitytype where myEventqualitytype.id = ?1"),
		@NamedQuery(name = "findEventqualitytypeByPrimaryKey", query = "select myEventqualitytype from Eventqualitytype myEventqualitytype where myEventqualitytype.id = ?1 "),

		@NamedQuery(name = "findEventqualitytypesByIds", query = "select myEventqualitytype from Eventqualitytype myEventqualitytype where myEventqualitytype.id in (?1)"),
		@NamedQuery(name = "findEventqualitytypeByPhyscialPrimaryKey", query = "select myEventqualitytype from Eventqualitytype myEventqualitytype where  myEventqualitytype.event.id = ?1 and myEventqualitytype.qualitytype.id = ?2 and myEventqualitytype.degree = ?3"),
		@NamedQuery(name = "countEventqualitytypesByName", query = "select count(myEventqualitytype)  from Eventqualitytype myEventqualitytype where myEventqualitytype.name like concat('%',?1,'%')") })
@Table(catalog = "ema", name = "eventqualitytype")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "ema/cn/edu/scau/cmi/ema/domain", name = "Eventqualitytype")
@XmlRootElement(namespace = "ema/cn/edu/scau/cmi/ema/domain")

public class Eventqualitytype implements Serializable, Comparable<Eventqualitytype> {

	private static final long serialVersionUID = 1L;

	@Column(name = "id", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@XmlElement
	Integer id;

	@Column(name = "name")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String name;

	@Column(name = "degree")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String degree;

	@Column(name = "description")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String description;
	@JSONField(serialize = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "event", referencedColumnName = "id", nullable = false) })
	@XmlTransient
	Event event;
	@JSONField(serialize = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "qualitytype", referencedColumnName = "id", nullable = false) })
	@XmlTransient
	Qualitytype qualitytype;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return this.id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return this.name;
	}

	public void setDegree(String degree) {
		this.degree = degree;
	}

	public String getDegree() {
		return this.degree;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return this.description;
	}

	public void setEvent(Event event) {
		this.event = event;
	}

	public Event getEvent() {
		return event;
	}

	public void setQualitytype(Qualitytype qualitytype) {
		this.qualitytype = qualitytype;
	}

	public Qualitytype getQualitytype() {
		return qualitytype;
	}

	public void copy(Eventqualitytype that) {

		setId(that.getId());

		setName(that.getName());
		setDegree(that.getDegree());
		setDescription(that.getDescription());

		setEvent(that.getEvent());

		setQualitytype(that.getQualitytype());

	}

	public Eventqualitytype() {

	}

	@Override
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");

		buffer.append("name=[").append(name).append("] ");
		buffer.append("degree=[").append(degree).append("] ");
		buffer.append("description=[").append(description).append("] ");

		return buffer.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Eventqualitytype))
			return false;
		Eventqualitytype comparedEventqualitytype = (Eventqualitytype) obj;
		if (!CheckPropertyEqual(this.event.id, comparedEventqualitytype.event.id)) {
			return false;
		}
		if (!CheckPropertyEqual(this.qualitytype.id, comparedEventqualitytype.qualitytype.id)) {
			return false;
		}
		if (!CheckPropertyEqual(this.degree, comparedEventqualitytype.degree)) {
			return false;
		}
		return true;
	}

	public static <T> boolean CheckPropertyEqual(T originProperty, T comparedProperty) {
		// 基本类型经过参数传递后会自动装箱
		String[] className = originProperty.getClass().getName().split("\\.");
		if (className[0].equals("java") && className[1].equals("math")) {
			return ((Comparable) originProperty).compareTo(comparedProperty) == 0 ? true : false;
		} else {
			return originProperty.equals(comparedProperty);
		}
	}

	@Override
	public int compareTo(Eventqualitytype o) {
		if (this.getId() > o.getId()) {
			return 1;
		} else if (this.getId() == o.getId()) {
			return 0;
		} else {
			return -1;
		}

	}
}
